import { ipcMain } from 'electron'
import { getUserList, addUser, updateUser, deleteUser, gardDeleteUser } from '../service/user'

/*
user-get-userList 查数据
user-add-userList 增数据
user-update-userList 改数据
user-delete-userList 软删数据
user-gard-delete-userList 硬删数据
*/

const userController = () => {
  ipcMain.handle('user-get-userList', async (event, params, userId = '') => {
    console.log(userId)

    try {
      const res = await getUserList(params, userId)
      return res
    } catch (error) {
      return []
    }
  })

  ipcMain.handle('user-add-user', async (event, data) => {
    try {
      const res = await addUser(data)
      return res
    } catch (error) {
      return await false
    }
  })
  ipcMain.handle('user-update-user', async (event, id, data) => {
    try {
      const res = await updateUser(id, data)
      return res
    } catch (error) {
      return await false
    }
  })
  ipcMain.handle('user-delete-user', async (event, id) => {
    try {
      const res = await deleteUser(id)
      return res
    } catch (error) {
      return await false
    }
  })
  ipcMain.handle('user-gard-delete-user', async (event, id) => {
    try {
      const res = await gardDeleteUser(id)
      return res
    } catch (error) {
      return await false
    }
  })
}

export default userController
